import threading

from loguru import logger

g_num = 0
mutex = threading.Lock()


def add_num1():
    global g_num
    for _ in range(1000000):
        mutex.acquire()
        g_num += 1
        mutex.release()
    logger.info(g_num)


def add_num2():
    global g_num
    for _ in range(1000000):
        mutex.acquire()
        g_num += 1
        mutex.release()
    logger.info(g_num)


if __name__ == '__main__':
    t1 = threading.Thread(target=add_num1)
    t2 = threading.Thread(target=add_num2)
    t1.start()
    t2.start()
    t1.join()
    t2.join()
    logger.info(g_num)
